package game;

import game.utils.StdIn;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Helen
 */
public class Game {
    
    GenericTreeNode<String> root;    
    
    public Game(){
        
    }
        
    public void play(){
        // TO-DO: for loops
        
        GenericTreeNode<String> node = root; 
        while(node.hasChildren())
        {
            System.out.println("Does it " + node.getData() + " [Y/N]");
            
            node = node.getChildAt(parseInput());
        }
    }
    
    private int parseInput()
    {
        int result = -1;
        String input = StdIn.readString();
        while(result != -1)
        {
            if(input.equalsIgnoreCase("Y"))
                result = 0;
            else if (input.equalsIgnoreCase("N"))
                result = 1;
            else
                System.out.println("Answer with either Y or N please");
        }
        return result;
    }
    public void createTree(){
        parseFile("database");
        root = new GenericTreeNode<String>("have 4 legs");
        GenericTreeNode<String> layEggs = new GenericTreeNode<String>("lay eggs");
        root.addChild(layEggs);
        GenericTreeNode<String> twoLegs = new GenericTreeNode<String>("have 2 legs");
        root.addChild(twoLegs);
    }
         
    private void parseFile(String filename) {
        try {
            BufferedReader br = new BufferedReader(new FileReader(filename));
            String line;
            while((line = br.readLine())!= null)
            {
                System.out.println(line);
            }
            br.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    public static void main(String[] args) {
        Game game = new Game();
        game.createTree();
        game.play();
    }
}
